package com.lh.runmanage.service.Impl;

import com.lh.runmanage.dao.ActiveMapper;
import com.lh.runmanage.model.InPutParam.ActiveInParam;
import com.lh.runmanage.service.ActiveService;
import com.lh.runmanage.unit.SeparateTableClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ：梁昊，后端工程师：梁昊
 * @create 2021-07-13 15:20
 * @function
 * @editLog
 */
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class ActiveServiceImpl implements ActiveService {
    @Autowired
    ActiveMapper activeMapper;
    @Autowired
    SeparateTableClass separateTableClass;

    @Override
    public <T> String getSeparateTableNo(T id, Class<T> tClass)    {
        Object object;
        if (tClass.getName() == "int")
            object = separateTableClass.getSeparateTableNo(id.toString());
        else
            object = separateTableClass.getSeparateTableNo(id.toString());
        return (String) object;
    }


    /**
     * 接收上传数据
     *
     * @param activeInParam com.lh.runmanage.model.InPutParam.ActiveInParam
     * @return 影响条数
     */
    @Override
    public int insertActive (ActiveInParam activeInParam) {
        activeInParam.setTableNo(this.getSeparateTableNo(activeInParam.getSeparateId(), String.class));
        if (activeMapper.insertActiveBeforeCheck(activeInParam) == 0)
            return activeMapper.insertActive(activeInParam);
        else
            return -1000;
    }

    /**
     * 接收上传数据
     *
     * @param activeInParam com.lh.runmanage.model.InPutParam.ActiveInParam
     * @return 影响条数
     */
    @Override
    public int insertActiveBeforeCheck(ActiveInParam activeInParam) {
        return activeMapper.insertActiveBeforeCheck(activeInParam);
    }
    /**
     * 删除历史数据
     *
     * @param activeInParam com.lh.runmanage.model.InPutParam.ActiveInParam
     * @return 影响条数
     */
    @Override
    public int deleteActiveFromCreate (ActiveInParam activeInParam) {
        activeInParam.setTableNo(this.getSeparateTableNo(activeInParam.getSeparateId(), String.class));
        return activeMapper.deleteActiveFromCreate(activeInParam);
    }

}